﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	HtmlTemplateFormatter.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;

namespace Smart.Common.Templates
{
	public class HtmlTemplateFormatter : TemplateFormatter
	{
		public HtmlTemplateFormatter(TemplateCtx ctx)
			: base(ctx)
		{
		}

		public override bool Format()
		{
			Ctx.Instance.Data = Format(Ctx.Template.Data);

			return true;
		}

		public override object Format(object template)
		{
			var strTemplate = template as string;

			if (strTemplate != null)
			{
				return
					strTemplate.ReplaceTags(Ctx.Values, Const.Template.TagSymbol);
			}

			throw new NotSupportedException();
		}
	}
}